import { ref, Ref } from "vue";

export interface UseCounterReturn {
  count: Ref<number>;
  increment: () => number;
  decrement: () => number;
  reset: () => number;
}

export function useCounter(initialValue = 0): UseCounterReturn {
  const count = ref(initialValue);

  const increment = () => count.value++;
  const decrement = () => count.value--;
  const reset = () => (count.value = initialValue);

  return {
    count,
    increment,
    decrement,
    reset,
  };
}
